<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/WEB-INF/views/import.jsp" flush="true" />
<%
	String path = request.getContextPath();
	String width = "180";
%>

<script type="text/javascript">
$(function() {
			
	//银行列表
	$("#bank").ligerComboBox({
         valueField: "key",
         textField: "value",
         autocomplete: function (e){ //模糊自动匹配
			filter_autoComboboxData(e.key, this);
			e.show();
		 }
	 });
	
	$.ajax({
		type: 'post',
		dataType:'json',
		url:'<%=path%>/account/fncGroupCompanyAccount/getBankList.do',
		success:function(msg){
			 if(msg){
				 	liger.get("bank").setData(msg);
				 	liger.get("bank").selectValue("${fncGroupCompanyAccountVO.bank}");
			 }else{
				 $.ligerDialog.SQalert({content:"开户银行加载失败", SQ_type: "error"});
			 }
		}
	});
	
});
			
</script>

</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">

					
					<div class="caption">
						<span class="title">所属公司</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">所属集团公司</div>
						<div class="field">
							<select id="groupCompanyId" name="groupCompanyId"
								ligerui="width: <%=width%>">
								<option value="">请选择</option>
								<c:forEach items="${fncGroupCompanyList}" var="fncGroupCompany">
									<option value="${fncGroupCompany.id}"
										<c:if test="${fncGroupCompany.id ==fncGroupCompanyAccountVO.groupCompanyId }">selected="selected"</c:if>>${fncGroupCompany.name}</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">账户归属部门</div>
						<div class="field">
							<select id="buOrgcd" name="buOrgcd" ligerui="width: <%=width%>"
								validate="{required:true}">
								<option value="">请选择</option>
								<c:forEach items="${buOrgCdList}" var="item">
									<option value="${item.key}"
										<c:if test="${item.key ==fncGroupCompanyAccountVO.buOrgcd }">selected="selected"</c:if>>${item.value}</option>
								</c:forEach>
							</select> *
						</div>
					</div>

					<div class="caption">
						<span class="title">账户信息</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">开户银行</div>
						<div class="field">
							<input id="bank" name="bank" type="text" class="ui-textbox"
								value="" placeholder="请选择" ltype="combobox"
								validate="{required:true}">*
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">开户银行名称</div>
						<div class="field">
							<input id="bankName" name="bankName" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								validate="{required:true}"
								value="${fncGroupCompanyAccountVO.bankName}" /> *
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">开户地(城市)</div>
						<div class="field">
							<jsp:include page="../../system/sysRegion/region.jsp"
								flush="true">
								<jsp:param name="regionShowLvl" value="2" />
							</jsp:include>
							*
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">开户银行地址(详细)</div>
						<div class="field">
							<input id="bankAddress" name="bankAddress" type="text"
								class="ui-textbox" validate="{required:true,maxlength:32}"
								value="${fncGroupCompanyAccountVO.bankAddress}" /> *
						</div>
					</div>

					<div class="fieldBox col_50">
						<div class="label">币种</div>
						<div class="field">
							<select id="currency" name="currency" ligerui="width: <%=width%>"
								validate="{required:true}">
								<option value="">请选择</option>
								<c:forEach items="${currencyList}" var="item">
									<option value="${item.key}"
										<c:if test="${item.key ==fncGroupCompanyAccountVO.currency}">selected="selected"</c:if>>${item.value}</option>
								</c:forEach>
							</select> *
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">账户性质</div>
						<div class="field">
							<select id="bankNature" name="bankNature"
								ligerui="width:<%=width%>" validate="{required:true}">
								<option value="">请选择</option>
								<c:forEach items="${bankNatureList}" var="item">
									<option value="${item.key}"
										<c:if test="${item.key ==fncGroupCompanyAccountVO.bankNature}">selected="selected"</c:if>>${item.value}</option>
								</c:forEach>
							</select> *
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">账户用途</div>
						<div class="field">
							<input id="bankUse" name="bankUse" type="text" class="ui-textbox"
								validate="{required:true,maxlength:32}"
								value="${fncGroupCompanyAccountVO.bankUse}" /> *
						</div>
					</div>



				<div class="fieldBox col_100">
					<div class="btnsBox">

						<c:if test="${operate == 'initiatorUpdate'}">
							<span id="saveBtn" class="sq-button sq-button-round"
								onclick="save('initiatorUpdate');">保存</span>
						</c:if>
						<c:if test="${operate == 'confirmAccountCancel'}">
							<span id="saveBtn" class="sq-button sq-button-round"
								onclick="save('confirmAccountCancel');">保存</span>
						</c:if>
						<c:if test="${operate == 'updateAll'}">
							<span id="saveBtn" class="sq-button sq-button-round"
								onclick="save('updateAll');">保存</span>
						</c:if>
					</div>
					</div>
					<div class="fieldBox col_100" style="display: none;">
						<div class="field">
							<input name="sysDate" id="sysDate" type="text" class="ui-textbox"
								value="${sysDate }"> <input name="loginUsrNm"
								id="loginUsrNm" type="text" class="ui-textbox"
								value="${loginUsrNm }">
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
	     
		$(function() {
			$("#ligerForm").ligerForm({
		        validate : true
		    });
			
			
			//设置省、市
            setRgnProvCdUpdataValue("${fncGroupCompanyAccountVO.bankProv}");
            setRgnCityCdUpdataValue("${fncGroupCompanyAccountVO.bankCity}");
            
	        <c:if test="${flowType == 'openAccount'}">
	        		//开户流程
	        	<c:if test="${operate == 'initiatorUpdate'}">
		        </c:if>
		        <c:if test="${operate == 'view'}">
		        	//查看:都不可修改
		        	setTopDisabled();
		        </c:if>
		        <c:if test="${operate == 'updateOpenAccount'}">
		      		//修改开户:除了开户信息,其他都不可修改
			        setTopDisabled();
		        </c:if>
		     <c:if test="${operate == 'updateAll'}">
	      		//修改全部
	        </c:if>
	       </c:if>
	        
	        
	     <c:if test="${flowType == 'closeAccount'}">
	    		//销户流程
	    	<c:if test="${operate == 'initiatorUpdate'}">
	    		//发起人修改
	        </c:if>
	        <c:if test="${operate == 'view' || operate == 'confirmAccountCancel'}">
	        	//查看:都不可修改
	        	setTopDisabled();
	        </c:if>
	    </c:if>
        
	    
	
	    });
		
		//上半部分不可用
		function setTopDisabled(){
			liger.get("groupCompanyId").setDisabled(true);
			liger.get("buOrgcd").setDisabled(true);
			liger.get("bank").setDisabled(true);
			liger.get("bankName").setDisabled(true);
			liger.get("bankAddress").setDisabled(true);
			liger.get("currency").setDisabled(true);
			liger.get("bankNature").setDisabled(true);
			
			
			liger.get("bankUse").setDisabled(true);
			liger.get("rgnProvCd").setDisabled(true);
			liger.get("rgnCityCd").setDisabled(true);
		}
		
		
		
		
		
		function save(operate){
			
			//验证
			var ligerForm = liger.get("ligerForm");
			if (!ligerForm.valid()) {
			    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
		            return ; 
		     }
			/*if($.trim($("#idCard").val()) == ""){
					$.ligerDialog.SQalert({content: "输入工号，点击'查找收件人'，查询出收件人（工号）和收件人（姓名）",SQ_type: "warning",SQ_showButtons: true});
					return ;
			} */ 
		   //填写开户信息
		   if(operate=='updateOpenAccount' || operate=='updateAll'){//校验开户信息必填项
			  var corpName=$('#corpName').val();//法人姓名
			  var corpPhone=$('#corpPhone').val();//法人预留电话
			  var operName=$('#operName').val();//经办人姓名	
			  var operPhone=$('#operPhone').val();// 经办人预留电话
			  if($.trim(corpName)==''){
					$.ligerDialog.SQalert({content: "请填写法人姓名!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  if($.trim(corpPhone)==''){
					$.ligerDialog.SQalert({content: "请填写法人预留电话!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  if($.trim(operName)==''){
					$.ligerDialog.SQalert({content: "请填写经办人姓名!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  if($.trim(operPhone)==''){
					$.ligerDialog.SQalert({content: "请填写经办人预留电话!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  //校验开户资料必填项
			  var ligergrid_file2=liger.get("ligergrid_file2");
			  var gridFile=ligergrid_file2.getData();
			  if (Object.keys(gridFile).length == 0) {
				  $.ligerDialog.SQalert({content: "请上传开户资料!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
		   }//end by 校验开户信息必填项
		   
			//组织数据，提交后台
			var data = ligerForm.getData();
				
			data["id"] = "${fncGroupCompanyAccountVO.id}";
			data["bankProv"] = data.rgnProvCd;//开户地-省
			data["bankCity"] = data.rgnCityCd;//开户地-市
			
			data["applUsrId"] = "${fncGroupCompanyAccountVO.applUsrId}";
			data["applOrgCd"] = "${fncGroupCompanyAccountVO.applOrgCd}";
			
			data["applCancelUsrId"] = "${fncGroupCompanyAccountVO.applCancelUsrId}";
			data["applCancelOrgCd"] = "${fncGroupCompanyAccountVO.applCancelOrgCd}";
			
			console.log(data);
			//return;
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/account/fncGroupCompanyAccount/save.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						alert(msg.info);
						//saveFile2('${fncGroupCompanyAccountVO.id}');
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
	//申请人确认邮寄 节点需填写“邮寄信息 运营专员确认接收  财务出纳确认接收
	function updatePostBtn(tabFlag){
		
		var handWay=$('#handWay').val();//交接方式
		var postInfo=$('#postInfo').val();//邮寄快递及单号
		var receiver=$('#receiver').val();//接收人
		var postData=$('#postData').val();//邮寄资料
		var onlineBankNum=$('#onlineBankNum').val();//网银数量
		var onlineBankSingle=$('#onlineBankSingle').val();//网银制单人
		var onlineBankReviewer=$('#onlineBankReviewer').val();//网银复核人
		
		if(tabFlag=='101'){//申请人确认邮寄 节点需填写“邮寄信息
			if($.trim(handWay)==''){
				$.ligerDialog.SQalert({content: "请填写交接方式!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
			if(handWay==2){
				if($.trim(postInfo)==''){
					$.ligerDialog.SQalert({content: "请填写邮寄快递及单号!",SQ_type: "warning",SQ_showButtons: true});
					return ;
				}
			}
			if($.trim(receiver)==''){
				$.ligerDialog.SQalert({content: "请填写接收人!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
			if($.trim(postData)==''){
				$.ligerDialog.SQalert({content: "请填写邮寄资料!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
			if($.trim(onlineBankNum)==''){
				$.ligerDialog.SQalert({content: "请填写网银数量!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
		}//end tabFlag=101
	  	if(tabFlag=='102'){//运营专员确认接收
		 	if($.trim(onlineBankReviewer)==''){
				$.ligerDialog.SQalert({content: "请填写网银复核人!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
	  	}	
	 	if(tabFlag=='103'){//财务出纳确认接收
			 if($.trim(onlineBankSingle)==''){
					$.ligerDialog.SQalert({content: "请填写网银制单人!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			}
		}
		//封装参数
		var data={
			"id":"${fncGroupCompanyAccountVO.id}",
			"handWay":handWay,
			"postInfo":postInfo,
			"receiver":receiver,
			"postData":postData,
			"onlineBankNum":onlineBankNum,
			"onlineBankSingle":onlineBankSingle,
			"onlineBankReviewer":onlineBankReviewer
		}
		var wait_dialog = null;
		$.ajax({
			type: 'post',
			dataType: 'json',
			data: data,
			url: '<%=path%>/account/fncGroupCompanyAccount/updatePartInfo.do',
			beforeSend : function() {
				wait_dialog = $.ligerDialog.SQalert({
					content : LogUtils.LOG_CMM_DATA_LOADING,
					SQ_type : "waitting"
				});
			},
			success : function(msg) {
				wait_dialog.close();
				if (msg.success == 1) {
					//alert(msg.info);
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				} else {
					$.ligerDialog.SQalert({
						content : msg.info,
						SQ_type : "error"
					});
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				wait_dialog.close();
				$.ligerDialog.SQalert({
					content : "网络错误，请稍后重试",
					SQ_type : "error"
				});
			}
		});
	}//end 
	//显示已上传但是未保存的文件列表
	function showFiles(data, index){
		var sysDate = $("#sysDate").val();
		var loginUsrNm = $("#loginUsrNm").val();
		var f_Grid = liger.get("ligergrid_file"+index);
		var uploadJOSN = data;
		for (var i=0; i< uploadJOSN.length; i++){ 
    		//添加行-追加行
    		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: i});
		}
	}
	//保存文件
	function saveFile2(pkId){
		var docArray = JSON.stringify(getUploadResultParams(2));
        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
    	if(null == docArray){
    		//无要上传的文件-直接结束
    		//top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
    	}else{
	        if(pkId){//ID不为空执行
		        //赋值附件
		        var data = {
					"docArray":docArray,
					"pkId": pkId,
					"flag": "accountData"
				};
				//请求
		        AjaxUtils.ajaxPost(url, data, function(msg){
		        	if(msg.success == 1){
						 //top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
						 if(msg.data){
							 clearUploadResultParams(2);
						 }
					 }else{
						 UIUtils.alertError(msg.info);
					 }
		        }, true);
	        }else{
	        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
	        }
    	}
	}	
	</script>
</body>
</html>